package com.study.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.study.model.jdao.ICategoryDAO;
import com.study.model.mdao.CategoryMapper;
import com.study.model.pojo.Category;

@Service
public class CategoryService {
	@Autowired
	ICategoryDAO dao;
	@Autowired
	CategoryMapper mapper;
	
	/**
	 * 根据id查询类别
	 * @param catId
	 * @return
	 */
	public Category findById(int catId) {
		return dao.findByCatId(catId);
	}
	
	/**
	 * 修改类别名称
	 * @param catid
	 * @param catname
	 * @return 
	 * @return 
	 */
	public void editcategory(int catId,String catName) {
		mapper.updateById(catId, catName);
	}
	
	public void deletecate(int catId) {
		mapper.updatedel(catId);
	}
	
	/**
	 * 查询所有
	 * @return
	 */
	public List<JSONObject> selectAll() {
		return mapper.selectAll();
	}
	
	/**
	 * 新增二级分类
	 * @param id
	 * @param lowname
	 */
	public void insert(int id,String lowname) {
		Category care = new Category();
		care.setCatName(lowname);
		care.setPid(id);
		care.setCatdel(1);
		dao.save(care);
	}
	
	/**
	 * 新增一级分类
	 * @param lowname
	 */
	public void insertOne(String lowname) {
		Category care = new Category();
		care.setCatName(lowname);
		care.setPid(0);
		care.setCatdel(1);
		dao.save(care);
	}
}
